package org.ipb.controller.modul.skkeputusan;

import org.ipb.model.SKKeputusan;

import util.hibernate.DAO;

import com.opensymphony.xwork2.ActionSupport;

public class ActionJQGridCrud extends ActionSupport {
	private static final long serialVersionUID = -5933849517817526086L;

	private String id;
	private String lembagaPembuatKeputusan;
	private String inisial;
	private String oper;

	public String getOper() {
		return oper;
	}

	public void setOper(String oper) {
		this.oper = oper;
	}

	public String execute() {
		if (getOper().equals("edit")) {
			return update();
		} else if (getOper().equals("add")) {
			return insert();
		} else {
			return delete();
		}
	}

	public String insert() {
		DAO<Integer> dao = new DAO<Integer>();
		SKKeputusan object = new SKKeputusan();
		object.setInisial(getInisial());
		object.setLembagaPembuatKeputusan(getLembagaPembuatKeputusan());
		dao.insert(object);
		dao.close();
		return SUCCESS;
	}

	public String update() {
		DAO<Integer> dao = new DAO<Integer>();
		SKKeputusan object = (SKKeputusan) dao.find(SKKeputusan.class,
				Integer.valueOf(getId()));
		object.setInisial(getInisial());
		object.setLembagaPembuatKeputusan(getLembagaPembuatKeputusan());
		dao.update(object);
		dao.close();
		return SUCCESS;
	}

	public String delete() {
		DAO<Integer> dao = new DAO<Integer>();
		SKKeputusan object = (SKKeputusan) dao.find(SKKeputusan.class,
				Integer.valueOf(getId()));
		dao.delete(object);
		dao.close();
		return SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getInisial() {
		return inisial;
	}

	public void setInisial(String inisial) {
		this.inisial = inisial;
	}

	public String getLembagaPembuatKeputusan() {
		return lembagaPembuatKeputusan;
	}

	public void setLembagaPembuatKeputusan(String lembagaPembuatKeputusan) {
		this.lembagaPembuatKeputusan = lembagaPembuatKeputusan;
	}

}
